<?php
/**
 * PersonalController
 * 
 * @author naspeh
 * @version $Id: PersonalController.php 670 2008-06-30 10:24:28Z naspeh $
 */
class PersonalController extends Core_Controller_Action
{
    /**
     * Авторизация
     *
     */
    public function loginAction ()
    {
        $form = new Core_Personal_LoginForm();
        $request = $this->getRequest();
        if ($form->isValid($request)) {
            Core_Message::add('Привет <b>' . Core_Auth::get('fullname') . '</b>');
            Core_Acl::start();
            $this->_redirect('/');
        }
        $this->view->form = $form;
    }
    /**
     * Регистрация
     *
     */
    public function signupAction ()
    {
        $form = new Core_Personal_SignupForm();
        $request = $this->getRequest();
        if ($form->isValid($request)) {
            $form->process();
            $this->_redirect('/');
        } 
        $this->view->form = $form;
    }
    /**
     * Завершение сеанса
     *
     */
    public function logoutAction() 
    {
        Core_Message::add('Досвидания <b>' . Core_Auth::get('fullname') . '</b>');
        Core_Auth::logout();
        Core_Acl::start();
        $this->_redirect('/');
        $this->_helper->viewRenderer->setNoRender();
    }    
    /**
     * Редактировать профиль
     *
     */
    public function profileAction()
    {
        $form = new Core_Personal_ProfileForm();
        $request = $this->getRequest();
        if ($form->isValid($request)) {
            $form->process();
            $this->_redirect($this->getRequest()->getRequestUri());
        } 
        $this->view->form = $form;
    }
    /**
     * Смена пароля
     *
     */
    public function passwordChangeAction()
    {
        $form = new Core_Personal_PasswordChangeForm();
        $request = $this->getRequest();
        if ($form->isValid($request)) {
            $form->process();
            $this->_redirect($this->getRequest()->getRequestUri());
        } 
        $this->view->form = $form;
    }
    /**
     * Смена email
     *
     */
    public function emailChangeAction()
    {
        $form = new Core_Personal_EmailChangeForm();
        $request = $this->getRequest();
        if ($form->isValid($request)) {
            $form->process();
            $this->_redirect($this->getRequest()->getRequestUri());
        } 
        $this->view->form = $form;
        $this->view->role = Core_Auth::get();
    }
    /**
     * Активация аккаунта
     *
     */
    public function activeAccountAction()
    {
        if (!Core_Auth::getEnableActive()) {
            throw new Core_Exception('activeDisabled#', 404);
        }
        $code = $this->_getParam('code');
        if (Core_Auth::activeRole($code)) {
            $this->_redirect('/');
        }
        $this->_helper->viewRenderer->setNoRender();        
    }
    /**
     * Активация нового email
     *
     */
    public function activeNewEmailAction()
    {
        $code = $this->_getParam('code');
        if (Core_Auth::activeNewEmail($code)) {
            $this->_redirect('/');
        }
        $this->_helper->viewRenderer->setNoRender();
    }  
}